<?php

class EvaluationAnnexesController extends AppController {

    var $name = 'EvaluationAnnexes';

    function index($evaluation_appraisal_id) {
        $this->layout = "ajax";
        $this->EvaluationAnnex->EvaluationAppraisal->recursive = -1;
        $this->set('evaluation_appraisal_id', $evaluation_appraisal_id);
        $this->set('property_id', $this->EvaluationAnnex->EvaluationAppraisal->find('first', array('conditions' => array('EvaluationAppraisal.id' => $evaluation_appraisal_id), 'fields' => array('EvaluationAppraisal.property_id'))));
        $this->set('annexes', $this->EvaluationAnnex->find('all', array('conditions' => array('EvaluationAnnex.evaluation_appraisal_id' => $evaluation_appraisal_id), 'order' => array('EvaluationAnnex.id'))));
    }

    function add($evaluation_appraisal_id) {
        $this->set('evaluation_appraisal_id', $evaluation_appraisal_id);
        if (!empty($this->data)) {
            if ($this->EvaluationAnnex->saveAll($this->data)) {
                $this->Session->setFlash("Datos guardados correctamente");
                $this->redirect(array('controller' => 'EvaluationAnnexes', 'action' => 'index', $evaluation_appraisal_id));
            }
        }
    }

    function edit($id) {
        if (empty($this->data)) {
            $this->EvaluationAnnex->recursive = -1;
            $this->data = $this->EvaluationAnnex->find('first', array('conditions' => array('EvaluationAnnex.id' => $id)));
        } else {
            if ($this->EvaluationAnnex->saveAll($this->data)) {
                $this->Session->setFlash("Datos editados correctamente");
                $this->redirect(array('controller' => 'EvaluationAnnexes', 'action' => 'index', $this->data['EvaluationAnnex']['evaluation_appraisal_id']));
            }
        }
    }

    function delete($id, $evaluation_appraisal_id) {
        if ($this->EvaluationAnnex->delete($id)) {
            $this->Session->setFlash("Datos borrados correctamente");
            $this->redirect(array('controller' => 'EvaluationAnnexes', 'action' => 'index', $evaluation_appraisal_id));
        } else {
            $this->Session->setFlash("Error tratando de borrar dato por favor intente mas tarde ");
            $this->redirect(array('controller' => 'EvaluationAnnexes', 'action' => 'index', $evaluation_appraisal_id));
        }
    }

}

?>
